The map is of all flight routes and airport information recorded by the OpenFlights. The original dataset contained all routes and airports all over the world, but for the purpose of displaying flight of China the data need to be cleaned and visualized.


The above map was generated by using the following code.

airport_url  <- "https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat"; 
route_url   <- "https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat"

airport_data_file <- "d:\\airports.dat"
route_data_file  <- "d:\\routes.dat"

if(!file.exists(route_data_file)) 
  download.file(route_url, destfile = route_data_file)
if(!file.exists(airport_data_file))
  download.file(airport_url,  destfile = airport_data_file)

data.port<- read.csv(airport_data_file,F)
data.line<- read.csv(route_data_file,F)

library(stringr)
# Find the airport information of China
portinchina <- str_detect(data.port[,'V4'], "China")
chinaport <- data.port[portinchina,]
# Delete the NA
chinaport <-chinaport[chinaport$V5!='',
                      c('V3','V5','V7','V8','V9')]
names(chinaport) <- c('city','code','lan','lon','att')

# Find the domestic flight of China

lineinchina <- (data.line[,'V3'] %in% chinaport$code) & (data.line[,'V5'] %in% chinaport$code)
chinaline <- data.line[lineinchina,c('V3','V5','V9')]
names(chinaline) <- c('source','destination','equipment')

# Function to get the lon and lat of airport
findposition <- function(code) {
  find <- chinaport$code==code
  x <- chinaport[find,'lon']
  y <- chinaport[find,'lan']
  return(data.frame(x,y))
}

# Convert the airport code to lat& lon
from <- lapply(as.character(chinaline$source),findposition)
from <- do.call('rbind',from)
from$group <- 1:dim(from)[1]
names(from) <- c('lon','lan','group')

to <- lapply(as.character(chinaline$destination),findposition)
to <- do.call('rbind',to)
to$group <-1:dim(to)[1]
names(to) <-c('lon','lan','group')
data.line <- rbind(from,to)
temp<- data.line[data.line$group<100,]

library(geosphere)

p1<- as.matrix(from[,c(1,2)])
p2<- as.matrix(to[,c(1,2)])
Line <- gcIntermediate(p1,p2,n=100,addStartEnd = TRUE, sp=TRUE)



library(leaflet)
m <- Line%>% leaflet() %>% setView(lng = 108.940178, lat = 34.341568, zoom=2)
m %>% addProviderTiles("CartoDB.DarkMatterNoLabels",options = ( providerTileOptions(minZoom = 2, maxZoom = 8))) %>%
  addCircleMarkers(weight = 1,
                   lat = chinaport$lan,
                   lng = chinaport$lon,
                   radius = 3,
                   group = "Airport",
                   color = "pink",
                   popup = paste("Airport Name:",chinaport$city,"<br>",
                                 "Code:",chinaport$code))%>%
   addPolylines(group="Flight Route",weight=0.3,opacity=0.5, color="magenta")%>% 
   addLayersControl(overlayGroups= c("Airport","Flight Route"),options=layersControlOptions(collapsed=FALSE))